package cn.uyunsky.platform.util.pl;

import cn.uyunsky.platform.util.PL;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateHelper {

    public String currentDate2String() {
        return new SimpleDateFormat(PL.TIMESTAMP_FORMAT).format(new java.util.Date());
    }
	
	public String currentDate2String(String format) {
		return new SimpleDateFormat(format).format(new java.util.Date());
	}

    /**
     * <pre>
     * 方法名称：
     * 功能描述：获取查询日期上一月
     * @param currMonth 当前月份,格式yyyyMM
     * @return
     * String
     * </pre>
     */
    public static String getLastMonth(String currMonth) {
        return getMonth(currMonth, -1);
    }

    public static String getNextMonth(String currMonth) {
        return getMonth(currMonth, 1);
    }

    private static String getMonth(String currMonth, int offer) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Calendar calendar = Calendar.getInstance();
        Date mydate = null;

        try {
            mydate = sdf.parse(currMonth);
        } catch (java.text.ParseException e) {
            e.printStackTrace();
            return null;
        }
        calendar.setTime(mydate);
        calendar.add(Calendar.MONTH, offer);
        return sdf.format(calendar.getTime());
    }

}
